<template>
    <div>
        <h1>食谱新增</h1>
        <table class="table">
            <tbody>
                <tr>
                    <td>项目名称</td>
                    <td><input type="text" v-model="info.Name"></td>
                </tr>
                <tr>
                    <td>服务人数</td>
                    <td><input type="text" v-model="info.porpel"></td>
                </tr>
                <tr>
                    <td>服务时长</td>
                    <td><input type="text" v-model="info.Time"></td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td><input type="radio" name="str" v-model="info.State" :value="true">启用
                        <input type="radio" name="str" v-model="info.State" :value="false">禁用
                    </td>
                </tr>

                <tr>
                    <td>分类</td>
                    <td><select v-model="info.KFId">
                            <option value="">请选择</option>
                            <option v-for="a in lisr" :value="a.Id">{{ a.KFName }}</option>
                        </select></td>
                </tr>

                <tr>
                    <td></td>
                    <td><input type="button" value="添加" @click="ok"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { useRouter } from 'vue-router';
import axios from 'axios';
const router = useRouter();
let info: any = reactive({
    "Id": 0,
    "Name": "",
    "Cord": "",
    "porpel": '',
    "Time": '',
    "State": '',
    "KFId": ""
})
let lisr: any = ref([]);
onMounted(() => {
    getlisr();
})
const getlisr = () => {
    axios({
        url: '/api/User/GetFL',
        method: 'get'
    })
        .then(res => {
            console.log(res);
            lisr.value = res.data
        })
        .catch(err => {
            console.log(err);

        })
}
//添加
const ok = () => {
    if (info.Name == "") {
        alert('项目名称不能为空')
        return;
    }
    if (info.porpel == "") {
        alert('服务人数不能为空')
        return;
    }
    let zhz = /^\d+$/
    if (zhz.test(info.porpel) == false) {
        alert('服务人数必须是整数判定 ')
        return;
    }
    if (info.Time == "") {
        alert('服务时长不能为空')
        return;
    }
    let zz = /^\d+$/
    if (zz.test(info.Time) == false) {
        alert('服务时长必须是整数判定 ')
        return;
    }
    if (info.State == "") {
        alert('状态不能为空')
        return;
    }
    if (info.KFId == "") {
        alert('分类不能为空')
        return;
    }
    axios({
        url: '/api/User/KFAdd',
        method: 'post',
        data: info
    })
        .then(res => {
            if (res.data > 0) {
                alert("添加成功");
                router.push('/kfshoe');
                return;
            }
            else {
                alert("添加失败");
                return;
            }
        })
        .catch(err => {
            console.log(err);

        })
}

</script>

<style scoped></style>